<?php

$targetFolder = '/Uploads'; // Relative to the root
$time = microtime(true);
if (!empty($_FILES)) {
	$tempFile = $_FILES['Filedata']['tmp_name'];
	$fileParts = pathinfo($_FILES['Filedata']['name']);
	$newName =  $time.'.'.$fileParts['extension'];
	$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
	$targetFile = rtrim($targetPath,'/') . '/' .$newName;
	
	// Validate the file type
	$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
	if (in_array($fileParts['extension'],$fileTypes)) {
		if(move_uploaded_file($tempFile,$targetFile)){
			echo $targetFolder."/".$newName;
		}else{
			echo 'error';
		}
	} else {
		echo 'error';
	}
}
?>